﻿// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
// for details on configuring this project to bundle and minify static web assets.

// Write your JavaScript code.

/**
* 部门经理AutoComplete文本框：格式化显示每一项
*/
function deptManagerACFormatItem(row) {
    return row[0];
}

/**
* 部门经理AutoComplete文本框：格式化群组显示每一项结果
*/
function deptManagerACFormatResult(row) {
    return row[0];
}

/**
* 域账号AutoComplete文本框：返回“cn|sam”格式的数据
*/
function getCnsamComplexstring(row) {
    return row[0] + "|" + row[1];
}

/**
* 域账号AutoComplete文本框：从“cn|sam”格式的数据提取sam并返回
*/
function getSamFromComplexstring(row) {
    if (row.length > 1) return row[1].trim();
    return row[0].trim();
}

/**
* 域账号AutoComplete文本框：从“cn|sam”格式的数据提取cn并返回
*/
function getCnFromComplexstring(row) {
    if (row.length > 1) return row[0].trim();
    return row[0].trim();
}

/**
* 只能输入数字和字母不能输入中文
*/
function onlyKeepNumberAndLetter(obj) {
    var value = $(obj).val();
    if (value != "") {
        $(obj).val(obj.value.replace(/[^\w\.\/]/ig, ''));
    }
}

/**
* 初始化流程审批记录
*/
var WorkflowNodeTableInit = function (url, workflowTypeId) {
    var oTableInit = new Object();
    //初始化Table
    oTableInit.Init = function () {
        $('#dataWorkflowNode').bootstrapTable({
            url: url,                           //请求后台的URL（*）
            method: 'get',                      //请求方式（*）
            striped: false,                     //是否显示行间隔色
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: false,                  //是否显示分页（*）
            sortable: false,                    //是否启用排序
            sortOrder: "asc",                   //排序方式
            queryParams: oTableInit.queryParams,//传递参数（*）
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                      //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            search: false,                      //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            searchOnEnterKey: true,
            strictSearch: true,
            showColumns: false,                 //是否显示所有的列
            showRefresh: false,                 //是否显示刷新按钮
            minimumCountColumns: 2,             //最少允许的列数
            clickToSelect: false,               //是否启用点击选中行
            //height: 800,                      //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "WorkflowRecordId",       //每一行的唯一标识，一般为主键列
            showToggle: false,                  //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
            detailView: false,                  //是否显示父子表
            columns: [
                {
                    field: 'WorkflowNodeName',
                    title: '流程环节',
                    halign: 'center'
                },
                {
                    field: 'Approver',
                    title: '处理人',
                    halign: 'center'
                },
                //{
                //field: 'nextCheckMan',
                //title: '下一步审批人',
                //halign: 'center'
                //},
                {
                    field: 'WorkflowTransitionName',
                    title: '状态',
                    halign: 'center'
                }, {
                    field: 'CreateDate',
                    title: '处理时间',
                    halign: 'center',
                    formatter: function (value, row, index) {
                        return getFormatDate(value)
                    }

                }, {
                    field: 'Remarks',
                    title: '审批结果描述',
                    halign: 'center'
                }],
            onLoadSuccess: function (res) {  //加载成功时执行
                //console.info("加载成功");
            },
            onLoadError: function () {  //加载失败时执行
                //console.info("加载数据失败");
            }
        });
    };

    //得到查询的参数
    oTableInit.queryParams = function (params) {
        var temp = {   //这里键的名字和控制器的变量名必须一致，如有变动此处和控制器要一起改
            limit: params.limit,   //页面大小
            offset: params.offset,  //页码
            workflowTypeId: workflowTypeId
            //search: params.search
        };
        return temp;
    };
    return oTableInit;
};

/**
将申请页面的按钮设置成不可点击状态
*/
function IndexBtnDisabled() {
    var btnSubmit = $("#btnSubmit");
    if (btnSubmit.length > 0) {
        btnSubmit.attr("disabled", "disabled");
    }

    //个人域账号申请页面特有的“新增行”按钮
    var btnAddNode = $("#btnAddNode");
    if (btnAddNode.length > 0) {
        btnAddNode.attr("disabled", "disabled");
    }

    //Add模态框中的提交和增加子表项按钮
    var btnAddSubmit = $("#btnAddSubmit");
    if (btnAddSubmit.length > 0) {
        btnAddSubmit.attr("disabled", "disabled");
    }
    var btnAddAddNode = $("#btnAddAddNode");
    if (btnAddAddNode.length > 0) {
        btnAddAddNode.attr("disabled", "disabled");
    }

    //Edit模态框中的提交和增加子表项按钮
    var btnAddSubmit = $("#btnEditSubmit");
    if (btnAddSubmit.length > 0) {
        btnAddSubmit.attr("disabled", "disabled");
    }
    var btnEditAddNode = $("#btnEditAddNode");
    if (btnEditAddNode.length > 0) {
        btnEditAddNode.attr("disabled", "disabled");
    }

    //用户界面分配角色的“提交”按钮
    var btnSetRoleSubmit = $("#btnSetRoleSubmit");
    if (btnSetRoleSubmit.length > 0) {
        btnSetRoleSubmit.attr("disabled", "disabled");
    }

    //角色界面分配资源的“提交”按钮
    var btnSetMenuSubmit = $("#btnSetMenuSubmit");
    if (btnSetMenuSubmit.length > 0) {
        btnSetMenuSubmit.attr("disabled", "disabled");
    }
}

/**
将申请页面的按钮设置成可点击状态
*/
function IndexBtnEnabled() {
    var btnSubmit = $("#btnSubmit");
    if (btnSubmit.length > 0) {
        btnSubmit.removeAttr("disabled");
    }

    //个人域账号申请页面特有的“新增行”按钮
    var btnAddNode = $("#btnAddNode");
    if (btnAddNode.length > 0) {
        btnAddNode.removeAttr("disabled");
    }

    //Add模态框中的提交和增加子表项按钮
    var btnAddSubmit = $("#btnAddSubmit");
    if (btnAddSubmit.length > 0) {
        btnAddSubmit.removeAttr("disabled");
    }
    var btnAddAddNode = $("#btnAddAddNode");
    if (btnAddAddNode.length > 0) {
        btnAddAddNode.removeAttr("disabled");
    }

    //Edit模态框中的提交和增加子表项按钮
    var btnAddSubmit = $("#btnEditSubmit");
    if (btnAddSubmit.length > 0) {
        btnAddSubmit.removeAttr("disabled");
    }
    var btnEditAddNode = $("#btnEditAddNode");
    if (btnEditAddNode.length > 0) {
        btnEditAddNode.removeAttr("disabled");
    }

    //用户界面分配角色的“提交”按钮
    var btnSetRoleSubmit = $("#btnSetRoleSubmit");
    if (btnSetRoleSubmit.length > 0) {
        btnSetRoleSubmit.removeAttr("disabled");
    }

    //角色界面分配资源的“提交”按钮
    var btnSetMenuSubmit = $("#btnSetMenuSubmit");
    if (btnSetMenuSubmit.length > 0) {
        btnSetMenuSubmit.removeAttr("disabled");
    }
}

/**
将审批页面的按钮设置成不可点击状态
*/
function AuditBtnDisabled() {
    var btnBackToStart = $("#btnBackToStart");
    if (btnBackToStart.length > 0) {
        btnBackToStart.attr("disabled", "disabled");
    }

    var btnSubmitToNext = $("#btnSubmitToNext");
    if (btnSubmitToNext.length > 0) {
        btnSubmitToNext.attr("disabled", "disabled");
    }

    var btnSubmitToComplete = $("#btnSubmitToComplete");
    if (btnSubmitToComplete.length > 0) {
        btnSubmitToComplete.attr("disabled", "disabled");
    }
}

/**
将审批页面的按钮设置成可点击状态
*/
function AuditBtnEnabled() {
    var btnBackToStart = $("#btnBackToStart");
    if (btnBackToStart.length > 0) {
        btnBackToStart.removeAttr("disabled");
    }

    var btnSubmitToNext = $("#btnSubmitToNext");
    if (btnSubmitToNext.length > 0) {
        btnSubmitToNext.removeAttr("disabled");
    }

    var btnSubmitToComplete = $("#btnSubmitToComplete");
    if (btnSubmitToComplete.length > 0) {
        btnSubmitToComplete.removeAttr("disabled");
    }
}

/**
将重新提交页面的按钮设置成不可点击状态
*/
function ResubmitBtnDisabled() {
    var btnResubmit = $("#btnResubmit");
    if (btnResubmit.length > 0) {
        btnResubmit.attr("disabled", "disabled");
    }

    var btnCancel = $("#btnCancel");
    if (btnCancel.length > 0) {
        btnCancel.attr("disabled", "disabled");
    }

    var addAddNode = $("#addAddNode");
    if (addAddNode.length > 0) {
        addAddNode.attr("disabled", "disabled");
    }
}

/**
将重新提交页面的按钮设置成可点击状态
*/
function ResubmitBtnEnabled() {
    var btnResubmit = $("#btnResubmit");
    if (btnResubmit.length > 0) {
        btnResubmit.removeAttr("disabled");
    }

    var btnCancel = $("#btnCancel");
    if (btnCancel.length > 0) {
        btnCancel.removeAttr("disabled");
    }

    var addAddNode = $("#addAddNode");
    if (addAddNode.length > 0) {
        addAddNode.removeAttr("disabled");
    }
}

/*获取当前时间：yyyy/MM/dd HH:mm:ss*/
function GetCurrentTime() {
    var currentTime = new Date();
    var year = currentTime.getFullYear();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var hour = currentTime.getHours();
    var minute = currentTime.getMinutes();
    var second = currentTime.getSeconds();
    return year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second;
}

/*用户是否为外协类型*/
function isWaixieType(prefix) {
    var wxtype = ["kf", "gw", "fw", "hw", "hp", "wx", "wy", "uv", "hw", "ds", "se", "ys"];
    var tempprefix = prefix.toLowerCase();
    for (var i = 0; i < wxtype.length; i++) {
        if (wxtype[i] == tempprefix) {
            return true;
        }
    }
    return false;
}

function patchcount(re, s) {
    re = eval("/" + re + "/ig")
    return s.match(re).length;
}

function checkADUserExists(_this, type) {
    var value = $(_this).val();
    var url = '/Ajax/CheckADUserExists';
    $.post(url, { type: type, samAccountName: value }, function (data) {
        if (data.existed) {
            alert("该工号已存在，请修改！");
            $(_this).val("");
            $(_this).focus();
            return;
        }
    });
}